﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;

namespace GUI
{
    public partial class Form_CapNhatSanPham : Form_CapNhatSanPhamBase
    {
        public Form_CapNhatSanPham()
        {
            InitializeComponent();
            Init();
        }
        public override void Init()
        {
            //trong ham nay minh viet them 1 ti de load du lieu cho combobox
            LoaiSanPhamBUS _bus = new LoaiSanPhamBUS();
            BindingSource _bind = new BindingSource();
            _bind.DataSource = _bus.GetData();
            cbo_LoaiSP.Properties.DataSource = _bind;
            repositoryItemLookUpEdit_LoaiSP.DataSource = _bind;

            //Hàm này để gửi các control xuông class ubBase để xử lý
            btnThem = btn_Them;
            btnXoa = btn_Xoa;
            btnSua = btn_Sua;
            btnClear = btn_Moi;
            _grid = grid_SanPham;

            base.Init();
        }
        public override void SetData(SanPham obj)
        {
            txt_TenSP.Text = obj.TenSP;
            txt_DonGia.Text = Utils.ToStr(obj.DonGia);
            txt_Cv.Text = Utils.ToStr(obj.CV);
            cbo_LoaiSP.EditValue = obj.MaLoaiSP;
            textEdit_MaSP.Text = obj.MaSP;
        }
        public override void GetData(ref SanPham obj)
        {
            obj.MaSP = textEdit_MaSP.Text;
            obj.TenSP = txt_TenSP.Text;
            obj.DonGia = Utils.ToFloat(txt_DonGia.Text);
            obj.CV = Utils.ToInt(txt_Cv.Text);
            obj.MaLoaiSP = Utils.ToStr(cbo_LoaiSP.EditValue);
        }
    }
    public class Form_CapNhatSanPhamBase : ucBase<SanPham, SanPhamBUS>
    {
    }
}
